package com.itqf.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/10/10
 * @Time: 下午5:13
 */
public class MyFirstInterceptor implements HandlerInterceptor {

    //常用  doChain
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("前.........");

        HttpSession httpSession = request.getSession();
        Object obj = httpSession.getAttribute("user");
        if (obj==null){
            response.sendRedirect("/login.jsp");
            return false;//getOrder
        }


        return true;//返回值决定是否放行  true:放行  false:不放行
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("后.........");

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("后  页面渲染完毕！！.........");
    }
}
